﻿package mortal.game.view.closedBetaGiftBagNew.panel
{
    import __AS3__.vec.*;
    import com.gengine.core.frame.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import fl.data.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.closedBetaGiftBagNew.*;
    import mortal.game.view.closedBetaGiftBagNew.cellRender.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;

    public class ClosedBetaOnlineGiftPanel extends ClosedBetaBasePanel
    {
        private var _onlineTimeBar:ClosedBetaOnlineTimeBar;
        private var _timer:SecTimer;
        private var _timeText:BitmapNumberText;
        private var _cellList:GTileList;
        private var _timeIcon1:GImageBitmap;
        private var _timeIcon2:GImageBitmap;
        private var _timeIcon3:GImageBitmap;
        private var _timeIcon4:GImageBitmap;
        private var _timeIcon5:GImageBitmap;
        private static const _timePointArr:Array = [{mins:0, value:0, per:(27 - 0) / ((5 - 0) * 60)}, {mins:5, value:27, per:(119 - 27) / ((20 - 5) * 60)}, {mins:20, value:119, per:(268 - 119) / ((60 - 20) * 60)}, {mins:60, value:268, per:(473 - 268) / ((120 - 60) * 60)}, {mins:120, value:473, per:(811 - 473) / ((240 - 120) * 60)}, {mins:240, value:811, per:(841 - 811) / ((255 - 240) * 60)}, {mins:255, value:841, per:0}];

        public function ClosedBetaOnlineGiftPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewBg3, 5, 30, this));
            this._onlineTimeBar = new ClosedBetaOnlineTimeBar();
            this._onlineTimeBar.x = 29;
            this._onlineTimeBar.y = 81;
            this._onlineTimeBar.setMaxTimeValue(841);
            this._onlineTimeBar.setTimeValue(0);
            this.addChild(this._onlineTimeBar);
            this._timeIcon1 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewTimePoint1, 29 - 13 + 27, 81 - 6, this);
            this._timeIcon2 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewTimePoint1, 29 - 13 + 119, 81 - 6, this);
            this._timeIcon3 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewTimePoint2, 29 - 13 + 268, 81 - 6, this);
            this._timeIcon4 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewTimePoint3, 29 - 13 + 473, 81 - 6, this);
            this._timeIcon5 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewTimePoint4, 29 - 13 + 811, 81 - 6, this);
            this._cellList = UIFactory.tileList(62, 411, 880, 400, this);
            this._cellList.setStyle("cellRenderer", ClosedBetaOnlineGiftCellRender);
            this._cellList.columnWidth = 176;
            this._cellList.rowHeight = 200;
            this._cellList.horizontalGap = 0;
            this._cellList.direction = GBoxDirection.VERTICAL;
            this._cellList.dataProvider = this.getOnLineGiftDataProvider();
            this._cellList.drawNow();
            this._timeText = UIFactory.bitmapNumberText(500, 126, "DoubleRewardTimerNum.png", 18.18, 27, 0, this, 10, BitmapNumberText.Mid);
            this._timeText.customCharIndex = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, ::10};
            this._timeText.text = "00:00:00";
            this._timer = new SecTimer();
            this._timer.addListener(TimerType.ENTERFRAME, this.updateTimeShow);
            this._timer.start();
            return;
        }// end function

        private function getOnLineGiftDataProvider() : DataProvider
        {
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.closedBetaOnlineGift.onlineGiftVec;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_1.addItem(_loc_2[_loc_3]);
                _loc_3++;
            }
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._onlineTimeBar.dispose(param1);
            this._timeText.dispose(param1);
            this._timeIcon1.dispose(param1);
            this._timeIcon2.dispose(param1);
            this._timeIcon3.dispose(param1);
            this._timeIcon4.dispose(param1);
            this._timeIcon5.dispose(param1);
            this._onlineTimeBar = null;
            this._timeText = null;
            this._timeIcon1 = null;
            this._timeIcon2 = null;
            this._timeIcon3 = null;
            this._timeIcon4 = null;
            this._timeIcon5 = null;
            if (this._timer && this._timer.running)
            {
                this._timer.stop();
                this._timer = null;
            }
            return;
        }// end function

        private function updateTimeShow(param1:Object) : void
        {
            if (isDisposed)
            {
                this._timer.stop();
                return;
            }
            var _loc_2:* = Cache.instance.closedBetaOnlineGift.OnlineTime;
            var _loc_3:* = _loc_2 / 60;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            while (_loc_7 < _timePointArr.length)
            {
                
                if (_loc_3 >= _timePointArr[_loc_7].mins)
                {
                    if (_loc_4 < _timePointArr[_loc_7].value)
                    {
                        _loc_4 = _timePointArr[_loc_7].value;
                        _loc_5 = _loc_7;
                    }
                }
                _loc_7++;
            }
            _loc_6 = (_loc_2 - _timePointArr[_loc_5].mins * 60) * _timePointArr[_loc_5].per + _loc_4;
            this._onlineTimeBar.setTimeValue(_loc_6);
            var _loc_8:* = _loc_2 / (60 * 60);
            _loc_2 = _loc_2 % (60 * 60);
            var _loc_9:* = _loc_2 / 60;
            _loc_2 = _loc_2 % 60;
            var _loc_10:* = _loc_2;
            var _loc_11:* = _loc_8.toString();
            var _loc_12:* = _loc_9.toString();
            var _loc_13:* = _loc_10.toString();
            if (_loc_11.length < 2)
            {
                _loc_11 = "0" + _loc_11;
            }
            if (_loc_12.length < 2)
            {
                _loc_12 = "0" + _loc_12;
            }
            if (_loc_13.length < 2)
            {
                _loc_13 = "0" + _loc_13;
            }
            this._timeText.text = _loc_11 + ":" + _loc_12 + ":" + _loc_13;
            return;
        }// end function

        override public function refresh() : void
        {
            this._cellList.dataProvider = this.getOnLineGiftDataProvider();
            this._cellList.drawNow();
            return;
        }// end function

    }
}
